package com.cyz.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cyz.service.UserService;
import com.cyz.service.impl.UserServiceImpl;

@Controller
@RequestMapping("/Login")
public class Login {
	
	@Resource(name="userServiceImpl")
	private UserService userService;
	
//	@Autowired
//	@Qualifier("userServiceImpl")
//	private UserService userService1;
	
	@RequestMapping("/login")
	public ModelAndView login(HttpServletRequest request,HttpServletResponse response) throws SQLException {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("login");
		return mv;
	}
	@RequestMapping("/validate")
	public void validate(HttpServletRequest request,HttpServletResponse response) throws IOException
	{
		PrintWriter printWriter =response.getWriter();
		String idNumber =request.getParameter("idNumber");
		System.out.println("idNumber"+idNumber);
		request.getSession().setAttribute("idNumber",idNumber);
		String password=request.getParameter("password");
//	    if(null!=userService.validate(idNumber))
//	    {
//	       if(password==userService.getPasswordByIdNumber(idNumber))
//	    	printWriter.write("{\"res\":\"1\"}");
//	       else
//	         printWriter.write("{\"res\":\"0\"}");
//	    }
//	    else
//	    {
//	    	printWriter.write("{\"res\":\"2\"}");
//	    }
		printWriter.write("{\"res\":\"1\"}");
	    printWriter.close();

	}

}
